CakePHP form $options['options']
Posted
by James
on Stack Overflow
See other posts from Stack Overflow
or by James
Published on 2010-04-08T02:07:20Z
Indexed on
2010/04/08
2:13 UTC
Read the original article
Hit count: 390
Hey! Total CakePHP noob here.
This is sort of a two fold question. In a view that is used for adding user
objects I would like to use a drop down (selection) field in the form.
Each user
belongs to a group
so when I add a user I want a drop down that contains all of the groups that the user could possibly join. Currently the group_id
field is a textfield. I know how to force it to be a selection field, but I don't know how to populate the selection with the names of the groups programmatically.
The Current method:
echo $form->input('group_id', array(
'1' => 'NameOfGroup1',
'2' => 'NameOfGroup2',
'3' => 'NameOfGroup3')
);
I want to generate the options array programmatically though.
echo $form->input('group_id', $this->Group->find('list'));
This doesn't work though. I get an error:
Undefined property: View::$Group [APP/views/users/add.ctp, line 8]
To me this means that I don't have access to the Group
object from inside my user view.
How can I accomplish this? Again, I want to do it programmatically so that it updates as I add groups or remove them.
© Stack Overflow or respective owner